package com.lc.user.express.httpserver;

import com.lc.user.express.model.AddrModel;
import com.lc.user.express.utils.Logger;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by Administrator on 2016/3/31.添加常用路线
 */
@HttpInlet(Net.GET_ADDR_ADD)
public class GetAddrAdd extends ZJDBAsyGet<Object> {
    public String userid,title,content;

    public GetAddrAdd(String userid,String title,String content, AsyCallBack listener) {
        super(listener);
        this.userid = userid;
        this.title = title;
        this.content = content;
    }

    @Override
    protected Object parser(JSONObject object) {
        if (object.optInt("message") == 1) {
            TOAST = "添加成功";
            return "1";
        } else {
            TOAST = "添加失败";
        }
        return null;
    }
    public static String addrListTojson(List<AddrModel> list){
        JSONArray json = new JSONArray();
        try {
            for(AddrModel model:list){
                JSONObject jo = new JSONObject();
                jo.put("address",model.getAddr());
                jo.put("name",model.getName());
                jo.put("mobile",model.getMobile());
                jo.put("point",model.getPoint());
                json.put(jo);

            }
        }catch (Exception e){
            e.printStackTrace();
            return  "";
        }
        return json.toString();
    }
}
